﻿<%@ Page Title="" Language="C#" MasterPageFile="~/SIPO.master" AutoEventWireup="true" CodeFile="recObjectionResponselist.aspx.cs" Inherits="SIPO.Web.Lists.Transaction.recObjectionResponse" %>

<asp:Content ID="Content1" ContentPlaceHolderID="body" Runat="Server">

<link type="text/css" rel="stylesheet" href="<%= ResolveUrl("~/styles/ui.jqgrid.css") %>" />
    <script type="text/javascript" src="<%= ResolveUrl("~/scripts/i18n/grid.locale-id.js") %>"></script>
    <script type="text/javascript" src="<%= ResolveUrl("~/scripts/jquery.jqGrid.min.js") %>"></script>
    <script src="<%= ResolveUrl("~/scripts/helper.js") %>" type="text/javascript"></script>
    
    <div>
    <button id="btnAdd" type="button" onclick="OpenForm('add');">
        Tambah</button>
    <button id="btnEdit" type="button" onclick="OpenForm('edit');">
        Ubah</button>
    
    </div>
    
    <br />
    <br />
    <table id="table" class="scroll" cellpadding="0" cellspacing="0">
    </table>
    <div id="pager" class="scroll">
    </div>
    <div id="dialog" title="Default dialog">
    </div>
    
    <script type="text/javascript">
        $("#btnAdd").button({ icons: { primary: "ui-icon-plus"} });
        $("#btnEdit").button({ icons: { primary: "ui-icon-pencil"} });
    </script>
    
    <script type="text/javascript">
        var handlerUrl = '<%= ResolveUrl("~/AjaxHandler/Transaction/recObjectionHandler.ashx") %>';
        $('#table').jqGrid({
            url: handlerUrl + '?method=getdataresponse',
            datatype: 'json',
            colNames: ['ObjectionId', 'Debitur', 'No Surat', 'Tanggal Surat', 'No. Sanksi', 'Tanggal Sanksi', 'Nilai Sanksi (Rp)', 'Nilai Keberatan (Rp)', 'Id Transaksi', 'No. STS', 'Tgl. STS', 'Catatan', 'Status', 'File STS'],
            colModel: [
                    { name: 'ObjectionID', hidden: true, index: 'ObjectionID', align: 'left', width: 100 },
                    { name: 'recDebtor.DebtorName', index: 'recDebtor.DebtorName', align: 'left', width: 100, searchoptions: { sopt: ['eq', 'cn']} },
                    { name: 'ObjectionNo', index: 'ObjectionNo', align: 'left', width: 100, searchoptions: { sopt: ['eq', 'cn']} },
                    { name: 'ObjectionDate', index: 'ObjectionDate', align: 'left', width: 100, formatter: 'date', formatoptions: { newformat: 'd M Y' }, searchoptions: { sopt: ['eq', 'cn']} },
                    { name: 'SanctionNo', index: 'SanctionNo', align: 'left', width: 100, searchoptions: { sopt: ['eq', 'cn']} },
                    { name: 'SanctionDate', index: 'SanctionDate', align: 'left', width: 150, formatter: 'date', formatoptions: { newformat: 'd M Y' }, searchoptions: { sopt: ['eq', 'cn']} },
                    { name: 'SanctionValue', index: 'SanctionValue', formatter: 'number', searchtype: 'number', align: 'right', width: 150 },
                    { name: 'ObjectionValue', index: 'ObjectionValue', formatter: 'number', searchtype: 'number', align: 'right', width: 150 },
                    { name: 'TransNo', index: 'TransNO', align: 'Left', width: 100, searchoptions: { sopt: ['eq', 'cn']} },
                    { name: 'ResponNo', index: 'ResponNO', align: 'Left', width: 100, searchoptions: { sopt: ['eq', 'cn']} },
                    { name: 'ResponDate', index: 'ResponDate', align: 'Left', width: 100, formatter: 'date', formatoptions: { newformat: 'd M Y' }, searchoptions: { sopt: ['eq', 'cn']} },
                    { name: 'ResponNote', index: 'ResponNote', align: 'Left', width: 100, searchoptions: { sopt: ['eq', 'cn']} },
                    { name: 'TransStatus', index: 'TransStatus', align: 'Left', width: 100, searchoptions: { sopt: ['eq', 'cn']} },
                    { name: 'ObjectionID', index: 'ObjectionID', align: 'center', width: 100, search: false, formatter: returnMyLink }

           	],
            rowNum: 10,
            id: 'ObjectionID',
            multiselect: true,
            rowList: [5, 10, 15, 20],
            pager: '#pager',
            sortname: 'recObjection.CreatedDate',
            sortorder: "desc",
            viewrecords: true,
            jsonReader: { repeatitems: false },
            width: 1250,
            height: '100%',
            caption: 'Tanggapan Sementara',
            ajaxGridOptions: { cache: false },
            ondblClickRow: function () {
                OpenForm('edit');
            }
        });

        function returnMyLink(cellValue, options, rowdata) {
            return "<a  href='#' onclick='downloadfile(" + cellValue + ")' >download</a>";
        }
        function downloadfile(cellValue) {
            var objrecImposition = new Object();
            objrecImposition.ObjectionID = encodeURIComponent(cellValue);
            jsonData = JSON.stringify(objrecImposition);
            var handlerUrl = '<%= ResolveUrl("~/ajaxhandler/loaddata/downloadhandler.ashx") %>';
            $.ajax({
                type: 'POST',
                url: handlerUrl + "?method=checkfilerespon",
                contentType: 'application/json',
                dataType: 'json',
                data: jsonData,
                success: function (data) {
                    if (data.IsSuccess) {
                        var win = window.open(handlerUrl + '?method=downloadrespon&ObjectionID=' + cellValue, '_blank');
                        win.focus();
                    }
                    else {
                        alert(data.Message);
                    }
                },
                error: function (response) {
                    //var r = JSON.parse(response.responseText);
                    alert("Error saat download file!"); //Message: " + r.Message);
                }
            });

        }

        $("#table").jqGrid('navGrid', '#pager', { edit: false, add: false, del: false, searchtext: 'Search', refreshtext: 'Refresh' },
        {}, {}, {}, { closeOnEscape: true, multipleSearch: true, closeAfterSearch: true });

        function OpenForm(ctl) {

            var formUrl = '<%= ResolveUrl("~/forms/Transaction/recObjectionResponseForm.aspx") %>';
            var grid = $('#table');
            var selIds = grid.jqGrid('getGridParam', 'selarrrow'),
                selText = [];
            selTextResponNo = [];
                        $.each(selIds, function () {
                            selText.push(grid.jqGrid('getCell', this, 'ObjectionID'));
                            selTextResponNo.push(grid.jqGrid('getCell', this, 'ResponNo'));
                        });




                        if (ctl == 'edit') {
                            if (selIds.length == 0) {
                                alert('Pilih data yang mau di ubah !');
                            }
                            else {
                                if (selIds.length > 1) {
                                    alert('Pilih satu record untuk ubah data.');
                                }
                                else if (selIds.length == 1 && selTextResponNo != '') {
                                    $('#dialog').load(formUrl + '?id=' + selText + '&menuId=' + '<%= base.MenuID %>' + '&isedit=1').dialog({ autoOpen: false, modal: true, width: 550, title: 'Ubah Tanggapan Sementara' });
                                    $("#dialog").dialog('open');
                                }
                                else {
                                    alert('Data yang anda pilih tidak dapat di edit!\nSilahkan tambahkan tanggapan sementara dahulu pada data tersebut.');
                                }
                            }
                        }

                        else if (ctl == 'add') {
                        if (selIds.length == 0) {
                            alert('Pilih data yang akan di tambah !');
                        }
                        else {
                            if (selIds.length > 1) {
                                    alert('Pilih satu data untuk di tambah.');
                                }
                            else if (selIds.length == 1 && selTextResponNo == '') {
                                $('#dialog').load(formUrl + '?id=' + selText + '&menuId=' + '<%= base.MenuID %>' + '&isedit=0').dialog({ autoOpen: false, modal: true, width: 550, title: 'Tambah Tanggapan Sementara' });
                                $("#dialog").dialog('open');
                            }
                            else {
                                alert('Data yang anda pilih sudah di tambahkan tanggapan sementara.');
                            }
                        } 
                            
                            
                        }

                        else {

                            if (selIds.length == 0)
                                alert('Pilih data yang mau di hapus !');
                            else {
                                var result = window.confirm('Benar data akan di hapus ?');
                                if (result) {

                                    var objrecPayment = new Object();
                                    //                        objrecPayment.PaymentID = encodeURIComponent(selText);
                                    //                        jsonData = JSON.stringify(objrecPayment);
                                    //                        CallAjax('<%= ResolveUrl("~/ajaxhandler/transaction/recPaymenthandler.ashx") %>', "?method=delete", jsonData);
                                    //                        setTimeout("$('#table').trigger('reloadGrid');", 3000);
                                }
                            }

                        }
        }
        
    </script>
    <br />
    <br />
    <br />
    <br />
</asp:Content>

